package com.smcdd.cdb.dbo.cdb_dbo.ui.activity;

import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.TextView;

import com.smcdd.cdb.dbo.cdb_dbo.R;
import com.smcdd.cdb.dbo.cdb_dbo.app.App;
import com.smcdd.cdb.dbo.cdb_dbo.service.presenter.WifiPresenter;
import com.smcdd.cdb.dbo.cdb_dbo.service.receiver.NetworkConnectChangedReceiver;
import com.smcdd.cdb.dbo.cdb_dbo.service.view.IWifiAc;
import com.smcdd.cdb.dbo.cdb_dbo.ui.base.BaseActivity;
import com.smcdd.cdb.dbo.cdb_dbo.ui.utils.ObtainUdis;
import com.smcdd.cdb.dbo.cdb_dbo.ui.widget.AwaitDialog;

import rx.functions.FuncN;

/**
 * 作者：Administrator on 2017/6/23 16:08
 * 邮箱：zhanghuaiha@gmail.com
 */

public class WifiActivity extends BaseActivity<IWifiAc,WifiPresenter> implements IWifiAc{
    private RecyclerView wifi_recycler;
    private ImageView back,refresh;
    private NetworkConnectChangedReceiver receiver;
    private TextView wifi_title;
    private String wifiSSID = "";
    private AwaitDialog selfDialog;

    @Override
    public void initView() {
        // 取得WifiManager对象
        wifi_recycler = (RecyclerView) findViewById(R.id.wifi_recycler);
        back = (ImageView) findViewById(R.id.wifi_back);
        refresh = (ImageView) findViewById(R.id.wufi_refresh);
//        IntentFilter filter = new IntentFilter();
//        receiver = new NetworkConnectChangedReceiver();
//        filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
//        filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
//        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
//        registerReceiver(receiver, filter);
        wifi_title = (TextView) findViewById(R.id.wifi_title);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (wifiSSID.contains("ChongDianDian")) {
            mPresenter.removeWifi(wifiSSID);
        }
    }

    @Override
    public void initData() {
        wifi_recycler.setLayoutManager(new LinearLayoutManager(this));
        mPresenter.loadContacts();
    }

    @Override
    public void initListener() {
        wifi_title.setOnClickListener(v -> {
            Intent intent = new Intent();
            intent.setAction("android.intent.action.VIEW");
            Uri content_url = Uri.parse("http://192.168.4.1/wifi_set.html");
            intent.setData(content_url);
            startActivity(intent);
        });
        refresh.setOnClickListener(v -> {
            mPresenter.loadData();
//            String udid = ObtainUdis.getUDID(WifiActivity.class);
//            mPresenter.selectImgs(udid);
        });
        back.setOnClickListener(v -> finish());
//        receiver.setItemClickListenter(name -> {
////            if (name != null && name.contains("ChongDianDian")) {
////                Intent intent = new Intent();
////                intent.setAction("android.intent.action.VIEW");
////                Uri content_url = Uri.parse("http://192.168.4.1/wifi_set.html");
////                intent.setData(content_url);
////                startActivity(intent);
//
//
////                    mPresenter.getMac2Ver();
////                    mPresenter.selectImgs(name);
////                    wifiSSID = name;
//            }
//        });
    }

//    public void Dialog(String msg){
//        selfDialog = new AwaitDialog(App.mContext);
//        selfDialog.setTitle("提示");
//        selfDialog.setMessage(msg);
//        selfDialog.show();
//    }

    @Override
    protected WifiPresenter createPresenter() {
        return new WifiPresenter(this);
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_wifi;
    }

    @Override
    public RecyclerView getRecycler() {
        return wifi_recycler;
    }

    @Override
    public WifiActivity getWifiAc() {
        return WifiActivity.this;
    }

}
